﻿#region CREDIT & LICENSE
/*******************************************
 * CREDIT: 
 * http://www.ROMPROS.com 
 * Tremendously helpful website, also would
 * like to give special thanks to:
 * 
 * Roverser - for the great effort on a c repository 
 * that most of this was ported from. http://code.google.com/p/rombot/
 * 
 * ROMeo - for the great amount of information shared
 * all across the rompros site. http://www.rompros.com/member.php?u=1901
 * 
 * 
 * LICENSE:
 *  
 * RomAPI is c# library is used to communicate directly with
 * the Runes Of Magic game client. 
 * 
 * Copyright (C) 2010  digitalxarts@gmail.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 *******************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;

using RomAPI.Offsets;
namespace RomAPI.Objects
{

    /// <summary>
    /// This class is used for players, monsters, npcs, basically everything that is alive in the game.
    /// </summary>
    public class RomUnit : RomObject
    {

        /// <summary>
        /// Constructor - passing client reference to parent (Object)
        /// </summary>
        /// <param name="client">client the object is being created for</param>
        /// <param name="baseAddress">base address (pointer) of this object</param>
        public RomUnit(RomClient client, uint baseAddress)
            : base(client, baseAddress)
        {

        }
        public double GetViewingAngle()
        {
            double x = VectorX;
            double y = VectorY;
            double degree = 0;
            if (x > 0) degree += 180;
            if (y > 0 && x > 0 || y < 0 && x < 0)
            {
                x = (x > 0) ? x - .999 : x + .999;
                degree += 90;
            }
            degree += Math.Abs(x) * 90;

            return degree;
        }
        public RomUnitId Id
        {
            get { return (RomUnitId)GetField<UInt32>((uint)RomUnitOffset.ID); }
        }
        public RomUnitType Type
        {
            get
            {
                //get the typeid
                uint typeid = GetField<UInt32>((uint)RomUnitOffset.TYPE_ID);
                //if the type id is greater 4 and less then zero... 
                //we don't know what it is. set it to zero (UNKNOWN)
                typeid = (typeid > 4 || typeid < 0) ? 0 : typeid;
                return (RomUnitType)typeid;
            }
        }
        public Byte IsAttackable
        {
            get { return GetField<Byte>((uint)RomUnitOffset.ATTACKABLE); }
        }
        public Byte InBattle
        {
            get { return GetField<Byte>((uint)RomUnitOffset.IN_BATTLE); }
        }
        public string Name
        {
            get { return GetStringField((uint)RomUnitOffset.NAME, 32); }
        }
        public string Guild
        {
            get { return GetStringField((uint)RomUnitOffset.GUILD, 32); }
        }
        public string Title
        {
            get { return GetStringField((uint)RomUnitOffset.TITLE, 32); }
        }
        public RomUnit Target
        {
            get { return new RomUnit(Client, BaseAddress + (uint)RomUnitOffset.TARGET); }
        }
        public float Speed
        {
            get { return GetField<float>((uint)RomUnitOffset.SPEED); }
        }
        public UInt32 Health
        {
            get { return GetField<UInt32>((uint)RomUnitOffset.HEALTH); }
        }
        public UInt32 HealthMax
        {
            get { return GetField<UInt32>((uint)RomUnitOffset.HEALTH_MAX); }
        }
        public UInt32 Level1
        {
            get { return GetField<UInt32>((uint)RomUnitOffset.LEVEL1); }
        }
        public RomUnitClass Class1
        {
            get { return (RomUnitClass)GetField<UInt32>((uint)RomUnitOffset.CLASS1); }
        }
        public UInt32 Power1
        {
            get { return GetField<UInt32>((uint)RomUnitOffset.POWER1); }
        }
        public UInt32 Power1Max
        {
            get { return GetField<UInt32>((uint)RomUnitOffset.POWER1_MAX); }
        }
        public UInt32 Level2
        {
            get { return GetField<UInt32>((uint)RomUnitOffset.LEVEL2); }
        }
        public RomUnitClass Class2
        {
            get { return (RomUnitClass)GetField<UInt32>((uint)RomUnitOffset.CLASS2); }
        }
        public UInt32 Power2
        {
            get { return GetField<UInt32>((uint)RomUnitOffset.POWER2); }
        }
        public UInt32 Power2Max
        {
            get { return GetField<UInt32>((uint)RomUnitOffset.POWER2_MAX); }
        }
        public UInt32 Stealth
        {
            get { return GetField<UInt32>((uint)RomUnitOffset.STEALTH); }
        }
        public RomUnitRace Race
        {
            get { return (RomUnitRace)GetField<UInt32>((uint)RomUnitOffset.STEALTH); }
        }
        public RomUnit Pet
        {
            get { return new RomUnit(Client, (uint)RomUnitOffset.STEALTH); }
        }
        public Byte IsAlive
        {
            get { return GetField<Byte>((uint)RomUnitOffset.STEALTH); }
        }
        public float X
        {
            get { return GetField<float>((uint)RomUnitOffset.X); }
        }
        public float Y
        {
            get { return GetField<float>((uint)RomUnitOffset.Y); }
        }
        public float Z
        {
            get { return GetField<float>((uint)RomUnitOffset.Z); }
        }
        public float VectorX
        {
            get { return GetField<float>((uint)RomUnitOffset.VECTOR_X); }
        }
        public float VectorY
        {
            get { return GetField<float>((uint)RomUnitOffset.VECTOR_Y); }
        }
        public float VectorZ
        {
            get { return GetField<float>((uint)RomUnitOffset.VECTOR_Z); }
        }

    }

}
